﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace PDS2
{
    /// <summary>
    /// Klass av Felix Östh
    /// </summary>
    class HUD
    {

        public bool hideHud = false;

        Player player;

        SpriteFont font;

        Vector2 position;

        Vector2 viewPort;
        Texture2D blank;

        public HUD(Player player, ContentManager content, Vector2 viewPort)
        {
            this.viewPort = viewPort;
            this.player = player;
            font = content.Load<SpriteFont>("Fonts/font");
            blank = content.Load<Texture2D>("blank");
        }

        public void Update(GameTime gameTime)
        {
            Movement(player.Position - new Vector2(viewPort.X - 670, viewPort.Y - 385));
        }

        void Movement(Vector2 pos)
        {
            float speed = Vector2.Distance(position, pos) / 13;
            Vector2 direction = Vector2.Normalize(pos - position);
            position += direction * speed;
        }

        public void Draw(SpriteBatch spriteBatch, float depth)
        {
            string dmg = string.Format("Damage: {0}", player.Damage);
            string hp = string.Format("Health: {0}", player.Health);

            Rectangle rect = new Rectangle((int)position.X - 5, (int)position.Y - 5, (dmg.Length + hp.Length) * 18, 50);

            if (!hideHud)
            {
                spriteBatch.Draw(blank, rect, new Color(0, 0, 0, 50));
                spriteBatch.DrawString(font, dmg, position, Color.LightGreen, 0f, Vector2.Zero, 1f, SpriteEffects.None, depth);
                spriteBatch.DrawString(font, hp + "    " + position, position + new Vector2(dmg.Length * 20, 0), Color.Red, 0f, Vector2.Zero, 1f, SpriteEffects.None, depth);
            }
        }
    }
}
